﻿using Microsoft.Build.Evaluation;
using OD.ProjectCustomizationTool.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace OD.ProjectCustomizationTool.Tools
{
    internal sealed class IconSetter : ProjectUpdaterFromQualityFileBase
    {
        #region Properties

        protected override string QualityFileName
        {
            get { return Properties.Resources.IconFileName; }
        }

        #endregion

        /// <summary>
        /// If the icon does not already exist, downloads it from the OD web site and stores
        /// it in the quality folder.
        /// </summary>
        protected override void InternalCreateQualityFile()
        {
            using (var client = new WebClient())
            {
                this.Monitor.Logger.WriteLine("Retrieving icon file from " + Properties.Resources.IconSourcePath + " to " + this.QualityFileFullPath);
                client.DownloadFile(Properties.Resources.IconSourcePath, this.QualityFileFullPath);
            }
        }

        /// <summary>
        /// Updates the project to consider the Viseo icon.
        /// <remarks>The icon is a link to .Quality common folder.</remarks>
        /// </summary>
        protected override void InternalUpdate()
        {
            this.SetProjectProperty(Properties.Resources.ApplicationIconProjectProperty, this.RelativePathToQualityFile);
        }

    }
}
